package com.firewolf.fr.s002_datatype;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.firewolf.fr.utils.FreeMarkerUtil;

import freemarker.template.Template;
import freemarker.template.TemplateException;
/**
 * 数据类型
 * @author liuxing
 *
 */
public class DataType {
	public static void main(String[] args) throws TemplateException, IOException {
		//数据模型
		Map<String, Object> root = new HashMap<>();
		
		//八大基本数据类型
		root.put("d1",3);
		root.put("d2", true);
		root.put("d3", 4.6);
		
		//字符串
		root.put("d4", "Hello World");
		
		//java.lang.Number如Integer
		root.put("d5", new Integer(56));
		root.put("d6", new Boolean(false));
		
		//List
		List<String> l = Arrays.asList(new String[]{"A","B","C"});
		root.put("d7",l);
		
		//Set
		Set<String> s = new HashSet<>();
		s.add("M");
		s.add("N");
		s.add("Q");
		root.put("d8",s);
		
		//数组
		String[] a = {"W","Y","Z"};
		root.put("d9",a);
		
		//Map
		Map<String,Object> map = new HashMap<>();
		map.put("name", "zhangsan");
		map.put("age", 90);
		root.put("d10", map);
		
		//JAVABean
		Dept d = new Dept();
		d.setName("部门名称");
		Employee e= new Employee();
		e.setD(d);
		e.setName("李四");
		root.put("d11", e);
		
		
		Template tl = FreeMarkerUtil.getTemplate("002_datatype.ftl");
		Writer w = new OutputStreamWriter(System.out);// 把数据显示到控制台
		tl.process(root, w);
		w.flush();
	}
}
